package com.example.hybridmobiledemo.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hybridmobiledemo.R;
import com.example.hybridmobiledemo.module.main.model.hospital.bean.Doctor;

import java.util.List;

public class DoctorAdapter extends RecyclerView.Adapter<DoctorAdapter.ViewHolder> {
    private List<Doctor> list;
    private Context context;

    public DoctorAdapter(List<Doctor> list, Context context){
        this.context = context;
        this.list = list;
    }
    @NonNull
    @Override
    public DoctorAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.doctor_item,parent,false);
        return new DoctorAdapter.ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull DoctorAdapter.ViewHolder holder, int position) {
            Doctor doctor = list.get(position);
            holder.doctorName.setText(doctor.getDoctorName());
            holder.doctorIntro.setText(doctor.getDoctorIntro());

    }

    @Override
    public int getItemCount() {
        if(list != null){
            return list.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView doctorName,doctorIntro;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            doctorName = itemView.findViewById(R.id.doctor_name);
            doctorIntro = itemView.findViewById(R.id.doctor_intro);
        }
    }
}
